<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm"  :inline="true" v-show="showSearch" size="small">
      <el-form-item label="流程名称" prop="instanceName">
        <el-input v-model="queryParams.instanceName" placeholder="请输入流程名称" clearable style="width: 240px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tastList">
      <!--      <el-table-column label="流程ID" align="center" prop="id"/>-->
      <el-table-column label="流程名称" align="center" prop="instanceName"/>
      <el-table-column label="任务节点名称" align="center" prop="name"/>
<!--      <el-table-column label="任务状态" align="center" prop="status"/>
      <el-table-column label="附件" align="center" prop="attachmentLink">
        <template slot-scope="scope"  v-if="scope.row.attachmentLink!=null">
          <a @click="preView(scope.row.attachmentLink)" target="_blank" class="buttonText" style="color: #00afff;text-decoration:underline">附件</a>
        </template>
      </el-table-column>-->
      <el-table-column label="办理人" align="center" prop="assignee"/>
      <el-table-column label="创建时间" align="center" prop="startTime">
        <template slot-scope="scope">
          <span>{{ formattedTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="办结时间" align="center" prop="endTime">
        <template slot-scope="scope">
          <span>{{ formattedTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-edit"
            @click="examineAndApprove (scope.row)"
            v-hasPermi="['workflow:leave:edit']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 其他审批单 -->
    <el-dialog title="审批" :visible.sync="otherOpen" v-if="otherOpen" width="500px" append-to-body>
      <el-form ref="otherForm" :model="otherForm" :rules="otherRules" label-width="120px">
        <el-row>
          <el-col :span="18">
            <el-form-item label="审批意见：">
              <el-radio-group v-model="otherForm.resource">
                <el-radio :label="1">同意</el-radio>
                <el-radio :label="0">不同意</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="批 注：">
              <el-input v-model="otherForm.note" type="textarea" :rows="3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
        <el-button @click="closeDelDialog">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 借阅审批单 -->
    <archiveBorrow title="借阅审批" :open="archiveBorrowOpen" istype="3" @closeDelDialog="closeDelDialog" ref="archiveBorrowRef"></archiveBorrow>

     <!-- 销毁审批单 -->
     <archiveDestroy title="销毁审批" :open="archiveDestroyOpen" istype="3" @closeDelDialog="closeDelDialog" ref="archiveDestroyRef"></archiveDestroy>

    <!-- 归档审批单 -->
    <archiveSave title="归档审批" :open="archiveSaveOpen" istype="3" @closeDelDialog="closeDelDialog" ref="archiveSaveRef"></archiveSave>

    <!-- 预归档审批单 -->
    <yarchiveSave title="预归档审批" :open="yarchiveSaveOpen" istype="3" @closeDelDialog="closeDelDialog" ref="yarchiveSaveRef"></yarchiveSave>

    <!-- 密级审批单 -->
    <!-- isType:1 代表从待办任务打开的 -->
    <archiveMjIdentify title="密级审批" :open="archiveMjIdentifyOpen" @closeDelDialog="closeDelDialog" ref="archiveMjIdentifyRef" isType="2"></archiveMjIdentify>

    <!-- 档案移交审批单 -->
    <!-- isType:1 代表从待办任务打开的  -->
    <archiveHandOver v-if="archiveHandOverOpen" :open="archiveHandOverOpen" @closeDelDialog="closeDelDialog" ref="archiveHandOverRef" :printRow="archiveHandOverRow" :printTitle='printTitle' :isType="isType" :printShow="printShow" :source="source"></archiveHandOver>
    <!-- 保管期限审批单 -->
    <!-- isType:1 代表从待办任务打开的 -->
    <archiveBgqxIdentify title="保管期限审批" :open="archiveBgqxIdentifyOpen" @closeDelDialog="closeDelDialog" ref="archiveBgqxIdentifyRef" isType="2"></archiveBgqxIdentify>
    <!-- 編輯发布 istype="1"   待办 istype="2"  已办 istype="3" -->
    <approve  title="编辑发布审批" :open="approveOpen" istype="3" @closeDelDialog="closeDelDialog" ref="approveRef"></approve>
  </div>
</template>

<script>


  import {listTask, formDataShow, formDataSave} from "@/api/activiti/hisTask";
  import leaveHistoryForm from "@/views/workflow/leave/leaveHistoryForm";
  import archiveBorrow from "@/views/archive/archiveBorrow/archiveBorrowReceipt/notQrocessed/approve"; // 借阅审批单
  import archiveDestroy from "@/views/archive/archiveDestroy/archiveDestroyReceipt/notQrocessed/approve"; // 销毁审批单
  import archiveSave from "@/views/archive/fileCollection/archiveApproval/notQrocessed/approve"; // 归档审批单
  import yarchiveSave from "@/views/archive/fileCollection/preArchiving/notQrocessed/approve"; // 预归档审批单
  import archiveMjIdentify from "@/views/archive/archivalAppraisal/classification/examineApprove/detail"; // 密级审批单
  import archiveHandOver from "@/views/archive/archiveTransfer/offline/printOrder.vue";//移交四性检测详情
  import archiveBgqxIdentify from "@/views/archive/archivalAppraisal/bgqxIdentify/bgqxExamineApprove/detail";
  import {getDicts_archive} from "@/api/archive/dict/dictManageData"; //保管期限审批单
  import approve from "@/views/archive/filesManage/editReleaseManage/approvalPending/approve.vue"
  export default {
    name: "Leave",
    components: {leaveHistoryForm, archiveBorrow, archiveSave, archiveMjIdentify, archiveHandOver, yarchiveSave, archiveBgqxIdentify,approve,archiveDestroy},
    data() {
      return {
        id:'',
        definitionKey: '',
        businessKey: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 请假表格数据
        tastList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          queryParams: undefined,
          pageNum: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {
          formData:[]
        },
        // 表单校验
        rules: {},
        // 流程字典
        flowPathOption: [],
        // 借阅审批
        archiveBorrowOpen: false,
        // 归档审批
        archiveSaveOpen: false,
        // 密级审批
        archiveMjIdentifyOpen: false,
        // 预归档审批
        yarchiveSaveOpen: false,
        // 移交单审批
        archiveHandOverOpen:false,
        // 保管期限审批
        archiveBgqxIdentifyOpen: false,
         // 销毁审批
         archiveDestroyOpen: false,
        //编辑发布审批
        approveOpen:false,
        // 其他审批
        otherOpen: false,
        otherForm: {
          resource: undefined,
          note: undefined
        },
        archiveHandOverRow:"",
        isType:"",
        printShow:"",
        printTitle:"",
       source : '',
        otherRules: {
          resource: [
            { required: true, message: "审批意见不能为空", trigger: "blur" }
          ]
        }
      };
    },
    created() {
      this.getList();
      this.getOption();
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      formattedTime(time) {
        return new Date(time).toLocaleString();
      },
      /** 查询请假列表 */
      getList() {
        this.loading = true;
        listTask(this.queryParams).then(response => {
          this.tastList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 获取流程定义字典
      getOption() {
        getDicts_archive('WORK_FLOW_KEY').then(response => {
          this.flowPathOption = response.data.map(item => {
            return {
              value: item.dictValue,
              label: item.dictLabel
            }
          })
        })
      },

      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.definitionKey = '',
          this.businessKey = '',
          this.form = {
            formData:[],
          };
        this.resetForm("form");
      },

      /** 审批按钮操作 */
      examineAndApprove(row) {
        console.log(row)
        this.reset();
        this.definitionKey = row.definitionKey;
        this.businessKey = row.businessKey;
        this.id=row.id;
        const obj = this.flowPathOption.find(item => item.label == row.definitionKey)
        console.log(obj)
        if(obj == undefined) {
          this.otherOpen = true
        } else {
          const str = obj.value
          // 借阅
          if(str == 'archiveBorrow') {
            this.$nextTick(() => {
              this.$refs.archiveBorrowRef.init(row);
            })
            this.archiveBorrowOpen = true
          } else if(str == 'archiveDestroy') {//销毁
              this.$nextTick(() => {
                  this.$refs.archiveDestroyRef.init(row);
              })
              this.archiveDestroyOpen = true
          }else if(str == 'archiveSave') { // 归档
            this.$nextTick(() => {
              this.$refs.archiveSaveRef.init(row);
            })
            this.archiveSaveOpen = true
          } else if(str == 'archiveMjIdentify') { // 密级
            this.$nextTick(() => {
              this.$refs.archiveMjIdentifyRef.activeName = '0'
              this.$refs.archiveMjIdentifyRef.init(row);
            })
            this.archiveMjIdentifyOpen = true
          } else if(str == 'archiveHandOver') { // 档案移交审批单
            this.$nextTick(() => {
              console.log(row,"skdlfjksldjfklsdjfklsdjfk")
              row.processVariables['otherVariables']=row.otherVariables;
              this.archiveHandOverRow = row.processVariables
              // this.$refs.archiveHandOverRef.init(row);
              this.isType="3"
              this.printShow=false;
              this.printTitle=""
              this.archiveHandOverOpen = true
            })
          } else if (str == 'yarchiveSave') { // 预归档
            this.$nextTick(() => {
              this.$refs.yarchiveSaveRef.init(row);
            })
            this.yarchiveSaveOpen = true
          } else if (str == 'archiveBgqxIdentify') { // 保管期限
            this.$nextTick(() => {
              this.$refs.archiveBgqxIdentifyRef.activeName = '0'
              this.$refs.archiveBgqxIdentifyRef.init(row);
            })

            this.archiveBgqxIdentifyOpen = true
          }else if(str == 'archiveOnlineReceive') { // 在线接收审批单
            this.$nextTick(() => {
              row.processVariables['otherVariables']=row.otherVariables;
              this.archiveHandOverRow = row.processVariables
              this.source = 'receivingApprovalRecords'
              // this.$refs.archiveHandOverRef.init(row);
              this.isType="3"
              this.printShow=false;
              this.printTitle=""
              this.archiveHandOverOpen = true
            })
          }else if(str == 'archiveBjfb') { // 编辑发布收审批单
            this.$nextTick(() => {
                this.$refs.approveRef.init(row);
            })
              this.approveOpen = true

          }
        }
        // formDataShow(row.id).then(response => {
        //
        //   // FormProperty_3qipis2--__!!radio--__!!审批意见--__!!i--__!!同意--__--不同意
        //   // FormProperty_0lffpcm--__!!textarea--__!!批注--__!!f--__!!null
        //   let datas = response.data;
        //   let formData = []
        //   for (let i = 0; i < datas.length; i++) {
        //     let strings = datas[i].split('--__!!')
        //     let controlValue = null
        //     let controlDefault = null
        //     switch (strings[1]) {
        //       case 'radio':
        //         controlValue = 1;
        //         controlDefault = strings[4]
        //         break;
        //       // default:
        //     }
        //     formData.push({
        //       controlId: strings[0],
        //       controlType: strings[1],
        //       controlLable: strings[2],
        //       controlIsParam: strings[3],
        //       controlValue: controlValue,
        //       controlDefault: controlDefault
        //     })
        //   }
        //   this.form.formData = formData;
        //   this.open = true;
        //   this.title = "审批";
        // });
      },
      closeDelDialog() {
        this.archiveBorrowOpen = false
        this.archiveSaveOpen = false
        this.yarchiveSaveOpen = false
        this.archiveMjIdentifyOpen = false
        this.archiveHandOverOpen = false
        this.archiveBgqxIdentifyOpen = false
        this.archiveDestroyOpen=false;
        this.approveOpen=false
        this.otherOpen = false
        this.queryParams.pageNum = 1
        this.isType="";
        this.printShow=""
        this.printTitle=""
        this.getList();
      },
      /** 提交按钮 */
      submitForm() {
        formDataSave(this.id,this.form.formData).then(response => {
          this.$modal.msgSuccess("审批成功");
          this.open = false;
          this.getList();
        });
      },
      /**文档预览**/
      preView(filePath){
        console.info(filePath);
        if (null == filePath || '' == filePath) {
          this.$alert('申请人没有上传哦', '消息提示', {
            confirmButtonText: '确定',
          });
        }else {
          // let originUrl = 'http://127.0.0.1:80/ruoyi-admin/';   //要预览文件的访问地址'
          window.open(filePath);
        }
        // const bb = originUrl  + aa;
        // window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(bb)));
      },
    }
  };
</script>
